import { mgop } from '@aligov/jssdk-mgop';
import store from "../store/index"
let baseURL = import.meta.env.VITE_VUE_DOMAIN;//公共api地址




export const request = (options) => {
  return new Promise((resolve, reject) => {
    let token = uni.getStorageSync('newcert-mobile-token');
    
    mgop({
      api:  options.url, // 必须
      host:import.meta.env.VITE_VUE_HOST,
      data:options.data,
      dataType: 'JSON',
      type:  'GET',
      appKey: import.meta.env.VITE_VUE_APPKEY, // 必须
      header: {
        'content-type': options.headers && options.headers['Content-Type'] ? options.headers['Content-Type'] : 'application/json',
         Authorization:'Bearer' + ' ' + token
      },
      onSuccess: data => {
        // uni.showModal({
        //   title:JSON.stringify(data)
        // })
        if (data.data.code == 200) {
          resolve(data.data);
        } else {
          uni.showToast({
            title: data.msg,
            icon: 'none',
            mask: true,
            duration: 2000
          });
        }
      },
      onFail: err => {
        reject(err)
      }
    });
  })
}
